package com.sx.ad.utils;

import com.sx.ad.exception.AdException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.time.DateUtils;

import java.text.ParseException;
import java.util.Date;

/**
 * @author zkx
 * @Date 2024/8/30 13:19
 */
public class CommonUtils {

	private static final String[] parsePatterns = {
			"yyyy-MM-dd","yyyy/MM/dd","yyyy.MM.dd"
	};

	public static String md5(String value) {
		return DigestUtils.md5Hex(value).toUpperCase();
	}

	public static Date parseStringDate(String dateString) throws AdException {
		try {
			return DateUtils.parseDate(dateString,parsePatterns);
		} catch (ParseException ex) {
			throw new AdException(ex.getMessage());
		}
	}
}
